package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author houChen
 * @date 2022/1/24 22:58
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/rabbitmq")
public class RabbitMQController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMsg")
    public String sendMessage(){
        for(long i=0;i<10;i++){
            OrderReturnReasonEntity content = new OrderReturnReasonEntity();
            content.setId(i);
            content.setName("消息"+i);
            rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", content, new CorrelationData(UUID.randomUUID().toString()));
            log.info("消息发送成功");
        }
        return "ok";
    }
}